import requests
import json

#如果返回为True，则说明有发货信息；否则说明没有发货信息
def has_extractor_info(sentence):
    data = {
        "confidence": 0.9,
        "extractInfoList": [
            {
                "confidence": 0.9,
                "id": 8,
                "name": "车长"
            },
            {
                "confidence": 0.9,
                "id": 9,
                "name": "车型"
            },
            {
                "confidence": 0.9,
                "id": 10,
                "name": "目的地"
            },
            {
                "confidence": 0.9,
                "id": 11,
                "name": "装货地"
            },
            {
                "confidence": 0.9,
                "id": 12,
                "name": "货名"
            },
            {
                "confidence": 0.9,
                "id": 13,
                "name": "重量"
            },
            {
                "confidence": 0.9,
                "id": 14,
                "name": "体积"
            },
            {
                "confidence": 0.9,
                "id": 15,
                "name": "装货时间"
            },
            {
                "confidence": 0.9,
                "id": 16,
                "name": "卸货时间"
            },
            {
                "confidence": 0.9,
                "id": 17,
                "name": "运费预算"
            },
            {
                "confidence": 0.9,
                "id": 18,
                "name": "备注"
            }
        ],
        "requestId": "9c2f5fc4-014d-4463-bfc3-91e41414ce46",
        "sentence": sentence
    }

    result = requests.post(url='https://predict-phantom.amh-group.com/cold-transportation-extractor/v1/models/cold-transportation-extractor:predict',json=data)
    if result.ok:
        content = result.text
        content = json.loads(content)
        slots = content['slots'] if 'slots' in content else []
        if slots:
            return True
    return False

if __name__ == '__main__':
    # sentence = '1、装货地：山东硕昌食品有限公司\n\n2、卸货地： 诸城市东环路60号\n3、货名：冰鲜鸡产品\n4、重量：5吨\n5、体积：？？\n6、需求车型：冷藏车\n7、装货时间 ：11月08日下午4点\n8、到货时间：11月09日早上7点\n9、发货人：\n10、收货人：\n11、预算费用：'
    sentence = '1、'
    print(has_extractor_info(sentence))
